<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\BaseController;
use app\admin\model\Banner;
use app\admin\model\Program;
use think\facade\Request;
use think\facade\View;

class Index extends BaseController
{
    public function index()
    {
        $value=Program::find(1);
        View::assign('value',$value);
        return view();
    }

    public function adv()
    {
        $list=Banner::field(true)->select();
        View::assign('list',$list);
        return view();
    }

    public function advEdit()
    {
        $id=Request::get('id','');
        $value=Banner::where('id',$id)->find();
        View::assign('value',$value);
        if (Request::isPost()){
            $post=Request::post();
            $img=Index::upload('logo','banner_img','md5');
            if (!empty($img)){
                $post['photo']=$img;
            }
            $edit=Banner::where('id','=',$id)->update($post);
            if ($edit){
                $this->success('修改成功',url('Index/adv'));
            }else{
                $this->error('修改失败');
            }
        }
        return view();
    }

    public function info()
    {
        if (Request::isPost()){
            $post=Request::post();
            $post['uptime']=time();
            $img=Index::upload('logo','info_img','md5');
            if (!empty($img)){
                $post['logo']=$img;
            }
            $update=Program::update($post);
            if ($update){
                $this->success('修改成功',url('Index/info'));
            }else{
                $this->error('网络波动,修改失败');
            }
        }
        $value=Program::find(1);
        View::assign('value',$value);
        return view();
    }

    public function pass()
    {
        return view();
    }
}
